<%@page import="org.ilead.iserve.service.manager.UserPermissionManager"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
	<head>
		<title>用户列表</title>
		
		<script type="text/javascript">
			function changePermission(obj){
				var permission = obj.options[obj.selectedIndex].value;
				
				//暂时先用这个方法获取，以后用更好的办法
				var childNodes = obj.parentNode.parentNode.childNodes;
				var count = 0;
				var urlObj;
				for (var i=0;i<childNodes.length;i++){
					if("td" == childNodes[i].nodeName.toLowerCase()){
						if(count == 7){
							var childNodes2 = childNodes[i].childNodes;
							for (var j=0;j<childNodes2.length;j++){
								if("a" == childNodes2[j].nodeName.toLowerCase()){
									urlObj = childNodes2[j];
									break;
								}
							}
							break;
						}
						count++;
					}
				}
				var url = urlObj.href;
				if(url.indexOf("&permission=") != -1)
					url = url.substring(0, url.length - 1) + permission;
				else
					url = url + "&permission=" + permission;
				urlObj.href = url;
			}
		</script>
	</head>
	
	<body id="listUserPage">
		<div align="center">
			<s:form action="listUser" method="post">

				<%--下面三句可以不动			--%>
				<s:hidden name="page"></s:hidden>
				<s:if test="#request.pageView.totalRecord">
					<table class="admin_table">
						<tr>
							<td>
								编号
							</td>
							<td>
								用户名
							</td>
							<td>
								姓名
							</td>
							<td>
								密码
							</td>
							<td>
								牧区
							</td>
							<td>
								小组
							</td>
							<td>
								权限
							</td>
							<td>
								操作
							</td>
						</tr>
						<s:iterator value="#request.pageView.records" id="entity">
							<tr>
								<td>
									<s:property value="#entity.id" />
								</td>
								<td>
									<s:property value="#entity.loginName" />
								</td>
								<td>
									<s:property value="#entity.userName" />
								</td>
								<td>
									<s:property value="#entity.password" />
								</td>
								<td>
									<s:property value="#entity.areaName" />
								</td>
								<td>
									<s:property value="#entity.groupName" />
								</td>
								<td>
									<s:select id="id" list="permissionList" name="#entity.permission" theme="simple" 
									key="permission" listKey="id" listValue="name" onchange="changePermission(this)"></s:select>
								</td>
								<td>
									<a
										href='<s:url action="updateUser"><s:param name="uid" value="#entity.id" />
										<s:param name="permission" value="" /></s:url>'>修改</a>&nbsp;
									<a onclick="return confirm('确定要删除吗？');"
										href='<s:url action="delUser"><s:param name="uid" value="#entity.id" /></s:url>'>删除</a>
								</td>
							</tr>
						</s:iterator>
					</table>
					<div class="page"><s:include value="/share/page.jsp" /></div>
				</s:if>
				<s:else>
				没有记录
				</s:else>
<%--				<p>--%>
<%--				<a href='<s:url action="beforeAddUser" />'>增加用户</a>--%>
<%--				</p>--%>
			</s:form>
		</div>
	</body>
</html>
